<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1" />
    <title>博雅诗词管理系统</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.css" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap-theme.css" crossorigin="anonymous">

    <script src="/js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="/bootstrap/js/bootstrap.js"></script>
    <link rel="stylesheet" th:href="@{/css/poem.css}">
</head>
<body>
    <!-- 导航 -->
    <nav class="navbar navbar-inverse navbar-fix-top" role="navigation">
        <div class="container" th:replace="fragments/header::header">
        </div>
    </nav>
    <div class="container">
        <div class="row">
            <div class="col-sm-4">
                <ul class="nav nav-list">
                    <li class="nav-header">
                        统计信息
                    </li>
                    <li class="active">
                        <a href="#">系统首页</a>
                    </li>
                    <li>
                        <a href="#">用户统计</a>
                    </li>
                    <li>
                        <a href="#">诗词统计</a>
                    </li>
                    <li class="nav-header">
                        审核管理
                    </li>
                    <li>
                        <a href="/admin/note/1">注释审核</a>
                    </li>
                    <li>
                        <a href="/admin/translate/1">译文审核</a>
                    </li>
                    <li>
                        <a href="/admin/appreciation/1">赏析审核</a>
                    </li>
                    <li>
                        <a href="/admin/story/1">故事审核</a>
                    </li>
                    <li class="divider">
                    </li>
                    <li>
                        <a href="#">系统帮助</a>
                    </li>
                </ul>
            </div>
            <div class="col-sm-8">
                <div class="row" style="margin: 20px;">
                    <form th:action="@{/admin/difficult}" method="post">
                        <div class="input-group">
                            <input type="text" class="form-control" id="keyWord" name="keyWord" placeholder="输入关键字">
                            <span class="input-group-btn">
                                <button class="btn btn-default" type="submit">搜索</button>
                            </span>
                        </div>
                    </form>
                </div>

                <section th:each="poetry : ${poetries}">
                    <div class="panel panel-primary">
                        <div class="panel-heading poem-title">
                            <h3 class="panel-title">
                                <a th:href="@{'/poetry/'+${poetry.id}}" th:text="${poetry.title}" target="_blank">静夜思</a></h3>
                        </div>
                        <div class="panel-body">
                            <div id="poetry-body">
                                <h6>
                                    <span th:text="${poetry.dynasty}"></span>:
                                    <a th:href="@{'/author/'+${poetry.authorid}+'/1'}" th:text="${poetry.author}" target="_blank">李白</a>
                                </h6>
                                <br>
                                <span th:text="${poetry.content}">
                                窗前明月光，疑是地上霜。<br>
                                举头望明月，低头思故乡。
                                </span>
                            </div>

                            <h5 class="page-header"></h5>
                            <div>

                                    <form class="form-inline" th:id="'dform'+${poetry.id}" th:action="@{/admin/setDifficult}" method="post">
                                        <div class="form-group">
                                            <label class="sr-only" for="difficult">难度系数</label>
                                            <input type="hidden" name="id" th:value="${poetry.id}">
                                            <input type="text" style="width: 200px;" class="form-control input-sm" id="difficult" name="difficult" placeholder="难度系数">
                                        </div>

                                        <button type="button" class="btn btn-default btn-sm btn-difficult" th:attr="pid=${poetry.id}">提交</button>
                                    </form>
                            </div>


                            <!--<button type="button" class="btn btn-default btn-xs active btn-verify" th:attr="pid=${poetry.id}">审核通过</button>-->
                        </div>
                    </div>
                </section>
            </div>
            </div>
        </div>
    </div>
    <div th:replace="fragments/footer::footer"></div>
    <script type="text/javascript">
        $(function () {

            //-- 修改难度系数
            $(".btn-difficult").on('click',function() {
                console.log("difficult....")
                var pid = $(this).attr("pid");
                var fname = "dform" + pid;
                var difficult = $("#"+fname + " input[name=difficult]").val();

                console.log("id="+pid);
                console.log("difficult="+difficult);

                var param = {};
                param.id = pid;
                param.difficult = difficult;

                $.post("/admin/setDifficult",param,function(result){
                    console.log(result);
                    if(result.result == 0) {
                        console.log("设置成功");
                        alert("设置成功");
                    }
                    else {
                        alert(result.msg);
                    }
                });

            });
        });
    </script>
</body>
</html>